package pre.Work;

public class Exam01{
    //创建两个线程，一个打印偶数，另一个打印奇数（范围从1到10）
    public static void main(String[] args) {
        Thread thread1 = new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i = 1; i < 11; i++) {
                    if (i % 2 == 0) {
                        System.out.println(Thread.currentThread().getName() + i);
                    }
                }
            }
        }, "子线程1偶数：");

        Thread thread2 = new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i = 1; i < 11; i++) {
                    if (i % 2 != 0) {
                        System.out.println(Thread.currentThread().getName() + i);
                    }
                }
            }
        }, "子线程2奇数：");
        thread2.start();
//        Thread.yield();
        try {
            thread2.join();
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        thread1.start();

    }
}
